package provider

import (
	"fmt"
	"ginfwk/infrastructure/component/cache"
	"ginfwk/infrastructure/component/cache/redis"
	"ginfwk/infrastructure/component/config"
	di "github.com/samber/do"
)

func RegisterCache() {
	di.Provide(di.DefaultInjector, func(*di.Injector) (cache.Cache, error) {
		var currentCache cache.Cache

		cfg := config.Global().Cache
		switch cfg.CacheType {
		case "redis":
			currentCache = redis.NewRedisCache(cfg)
		default:
		}
		if currentCache == nil {
			return nil, fmt.Errorf("not support cache type: [%s]\n", cfg.CacheType)
		}

		return currentCache, nil
	})
}
